<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { AirDistribution, getAirportCity } from '@/api/home'
import testMap from './components/center-map.vue'
const mapData = ref([
])

const airNumObj = ref({
  airportCount: 0,
  debuggingAirportCount: 0,
  runningAirportCount: 0
})
const getAirNumber = async () => {
  const res = await AirDistribution()
  airNumObj.value.debuggingAirportCount = res.data.debuggingAirportCount
  airNumObj.value.airportCount = res.data.airportCount
  airNumObj.value.runningAirportCount = res.data.runningAirportCount
}

function getProvinceCode(provinceName) {  
  const provinceMap = {  
    '江苏': 'js',  
    '河南': 'hn',  
    '广东': 'gd',  
    '湖南': 'hunan',  
    '海南': 'hainan',  
    '贵州': 'guizhou',  
    '陕西': 'shanxi',  
  };  

  // 找到第一个匹配的省份  
  const matchedProvince = Object.keys(provinceMap).find(key => provinceName.includes(key));  

  // 返回对应的代码，如果没有匹配则返回默认值  
  return matchedProvince ? provinceMap[matchedProvince] : '';  
}  
const getAirportOfCity = async () => {
  const res=await getAirportCity()

  const originData=res.data

  const transformedData = originData.map(item => {  
  const provinceName = Object.keys(item)[0];  
  const provinceData = item[provinceName];  

  // 根据省份名称映射到目标结构  
  return {  
    name: provinceName.replace('省', ''), // 去掉“省”字  
    airportCount: provinceData.airportCount, // 使用原始数据中的值  
    flyingCount: provinceData.flyingCount ,// 使用原始数据中的值  
    // province: provinceName.includes('江苏') ? 'js' : 'gz' // 使用省份名称判断  
    province: getProvinceCode(provinceName), // 使用映射函数  
      titColor: 'g'

    
  };  
 
});  
  mapData.value = transformedData

}
onMounted(() => {
  // 获取全国机场分布
  getAirNumber()
  // 按照城市获取机场数据
  // getAirportOfCity()
})
</script>

<template>
  <div class="md-con">
   
    <div class="map-box">
      <!-- 全国机场分布情况 -->
      <div class="airport_points">
        <div class="hd">
          <h2 class="tit">全国机场分布情况</h2>
        </div>
        <div class="points_bd">
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon1.png" alt="" />
            <div class="info">
              <h3 class="tit">全部机场</h3>
              <p class="quantity">{{ airNumObj.airportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon2.png" alt="" />
            <div class="info">
              <h3 class="tit">任务中机场</h3>
              <p class="quantity">{{ airNumObj.runningAirportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon3.png" alt="" />
            <div class="info">
              <h3 class="tit">调试中机场</h3>
              <p class="quantity">{{ airNumObj.debuggingAirportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
        </div>
      </div>
    </div>
     <!-- 背景 -->
     <div class="bg-animation">
      <div class="bg-1" style="display: flex; justify-content: center; align-items: center">
      </div>
      <testMap/>

    </div>
  </div>
</template>

<style lang="less" scoped>
.md-con {
  position: relative;
  flex: 1;
  margin: 0 15px;
  overflow: hidden;
  .bg-animation {
    z-index: 10;

    .bg-1 {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: url(@/assets/bit-screen/run_home_bg.png) no-repeat center;
      background-size: 110%;
    
    }
    .bg-2 {
      position: absolute;
      z-index: 1;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
     
    }
  }
  .map-box {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 150px;
  }
  .airport_points {
    width: 55%;
    flex-direction: column;
    margin-top: 15px;
    .hd {
      display: flex;
      justify-content: space-between;
      margin-bottom: 15px;
      color: #daeef9;
      .tit {
        font-weight: bold;
        font-size: 20px;
      }
      .date {
        font-size: 14px;
      }
    }
    .points_bd {
      display: grid;
      width: 100%;
      height: 80px;
      grid-template-columns: repeat(3, 1fr);
      grid-column-gap: 2.5%;
      .group {
        display: grid;
        flex: 1;
        grid-template-columns: 60px auto;
        grid-column-gap: 6px;
        width: 100%;
        height: 100%;
        background: url(@/assets/bit-screen/points_bg.png) no-repeat center;
        background-size: 100% 100%;
        img {
          align-self: center;
          width: 80%;
          margin: 0 auto;
        }
        .info {
          place-self: center start;
          .tit {
            font-size: 15px;
            color: #ffffff;
            text-shadow: 1px 2px 0px rgba(17, 20, 22, 0.22);
            font-style: italic;
            color: #ffffff;
            line-height: 27px;
            text-shadow: 1px 2px 0px rgba(17, 20, 22, 0.22);
            font-style: italic;
            font-family: PingFang SC;
          }
          .quantity {
            font-family: Roboto;
            font-weight: bold;
            font-size: 22px;
            font-style: italic;
            background: linear-gradient(
              80deg,
              rgba(29, 128, 224, 0.64) 0%,
              rgba(255, 255, 255, 0.64) 40%,
              rgba(255, 255, 255, 0.64) 100%
            );
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            span {
              font-size: 14px;
            }
          }
        }
      }
    }
  }
}
@keyframes rotate1 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
@keyframes rotate2 {
  from {
    transform: rotate(360deg);
  }
  to {
    transform: rotate(0deg);
  }
}

@keyframes dot-animation {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(0.8) translate(0, 5px);
  }
  100% {
    transform: scale(1) translate(0, 0);
  }
}
// @media screen and (min-height: 1040px) {
//   .map_wrap .map_con .map {
//     bottom: 10% !important;
//   }
// }
@media screen and (max-width: 1700px) {
  .airport_points {
    width: 65% !important;
  }
}
@media screen and (max-width: 1400px) {
  .airport_points {
    width: 80% !important;
  }
}
</style>
